<template>
  <div class="home-container">
    <!-- 头部搜索栏 -->
    <van-nav-bar class="toutiao-nav-bar">
      <van-button
        class="searchBtn"
        slot="title"
        type="info"
        size="small"
        round
        icon="search"
        to="/search"
        >搜索</van-button
      >
    </van-nav-bar>
    <!-- /头部搜索栏 -->

    <!-- 滚动导航 -->
    <van-tabs
      title-active-color="#333"
      title-inactive-color="#777"
      line-height="6"
      line-width="31"
      class="tabs"
      color="#3296fa"
      :swipeable="true"
    >
      <van-tab v-for="item in channels" :key="item.id" :title="item.name">
        <!-- 文章列表 -->
        <articles :channel="item"></articles>
        <!-- /文章列表 -->
      </van-tab>

      <!-- 汉堡导航 -->
      <div class="tianchong" slot="nav-right"></div>
      <div class="hamburger-Btn" slot="nav-right" @click="show = true">
        <i class="iconfont icon-gengduo"></i>
      </div>
    </van-tabs>

    <!-- 频道编辑模块，底部弹出层 -->
    <van-popup
      v-model="show"
      position="bottom"
      :style="{ height: '100%' }"
      closeable
    >
      <editchannel :userChannels='this.channels'></editchannel>
    </van-popup>
  </div>
</template>

<script>
import { getUserChannels } from '@/api/index.js'
import articles from '@/views/home/components/articles' // 引入文章列表组件
import editchannel from './components/editchannel' // 引入频道弹出层组件
export default {
  data() {
    return {
      // 定义列表相关变量
      list: [],
      loading: false,
      finished: false,
      channels: [],
      // 控制弹出层
      show: false
    }
  },
  components: {
    articles: articles,
    editchannel
  },
  mounted() {
    this.getChannels()
  },
  methods: {
    // 1.查询频道列表
    async getChannels() {
      const res = await getUserChannels() // 发送ajax请求
      this.channels = res.data.data.channels // 接收返回频道列表
    }
  }
}
</script>

<style lang="less">
.home-container {
  // 设置底部内填充使列表上限提示能显示
  padding-bottom: 100px;

  // 头部搜索栏
  .van-nav-bar__title {
    max-width: unset; // 不限制输入框最大宽度
  }
  .searchBtn {
    width: 555px;
    height: 64px;
    background-color: #5babfb;
    border: none;
    font-size: 28px;

    .van-icon {
      color: #fff;
      font-size: 32px;
    }
  }
  // 滚动导航条
  .tabs {
    // 单个标签tab样式
    .van-tabs__nav {
      height: 83px;
    }
    .van-tab {
      width: 200px;
      height: 80px;
      border-right: solid #edeff3 1px;
    }
    // 底部条样式
    .van-tabs__line {
      bottom: 9px;
    }
    // 清除底部内填充
    .van-tabs__nav--line {
      padding-bottom: unset;
    }
    // 汉堡按钮
    .hamburger-Btn {
      position: fixed;
      right: 0;
      width: 66px;
      height: 82px;
      background-color: #ffffff;
      opacity: 0.9;
      .iconfont {
        line-height: 82px;
        font-size: 40px;
        color: #333;
      }
    }
    .hamburger-Btn::before {
      content: '';
      position: absolute;
      left: 0;
      width: 2px;
      height: 100%;
      background-image: url(~@/assets/gradient-gray-line.png);
      background-size: contain;
    }
    .tianchong {
      flex-shrink: 0; // 默认为1，会评分flex布局宽度，所以设为0关闭此属性
      width: 66px;
      height: 82px;
    }
  }
}
</style>
